/**
 * AirportListResource.java
 * Jan 5, 2010
 */
package com.dlplay.flightinfo.server.resource;

import java.io.IOException;
import java.util.List;
import java.util.logging.Level;

import org.restlet.data.MediaType;
import org.restlet.ext.xml.DomRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;

import com.dlplay.flightinfo.core.FlightSystem;
import com.dlplay.flightinfo.data.Airport;
import com.dlplay.flightinfo.presentation.XMLAirportListGenerator;
import com.dlplay.flightinfo.presentation.XMLGenerator;

/**
 * @author zhao yu
 *
 */
public class AirportListResource extends ServerResource {
	/**
	 * Returns a listing of all registered Flight Number.
	 */
	@Get("xml")
	public Representation toXml() {
		getLogger().info("toXml");
		// Generate the right representation according to its media type.
		DomRepresentation representation;
		try {
			representation = new DomRepresentation(
					MediaType.TEXT_XML);
			List<Airport> entries = FlightSystem.getAirportManager().getAirportList();
			XMLGenerator xmlgenerator = new XMLAirportListGenerator(entries);
			xmlgenerator.generate(representation.getDocument());
			return representation;
		} catch (IOException e) {
			getLogger().log(Level.SEVERE, "Create DomRepresentation Failed");			
			e.printStackTrace();
		}			
		return null;		
	}	
}
